package com.cdl.library.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.cdl.library.R;


public class QrImageView extends RelativeLayout {

    View view;
    ImageView iv_qr;
    ProgressBar progressBar;
    LinearLayout layout_error;
    TextView tv_error_desc;


    public QrImageView(Context context) {
        this(context, null);
    }

    public QrImageView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 1);
    }

    public QrImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        view = LayoutInflater.from(getContext()).inflate(R.layout.view_qr_imageview, this, true);
        iv_qr = findViewById(R.id.iv_qr);
        progressBar = findViewById(R.id.progressBar);
        layout_error = findViewById(R.id.layout_error);
        tv_error_desc = findViewById(R.id.tv_error_desc);
    }

    public void setImageBitmapShow(Bitmap bitmap) {
        progressBar.setVisibility(GONE);
        layout_error.setVisibility(GONE);
        iv_qr.setVisibility(VISIBLE);
        iv_qr.setImageBitmap(bitmap);
    }

    public void setImageErrorShow(String errorDesc) {
        progressBar.setVisibility(GONE);
        iv_qr.setVisibility(VISIBLE);
        layout_error.setVisibility(VISIBLE);
        tv_error_desc.setText(errorDesc);
    }

}
